package ch.unisi.inf.gui.action;

import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.filechooser.FileView;


/**
 * 
 * @author Mohamed.Mosa@lu.unisi.ch
 * This class is responsible for associating the icon image with 
 * each image based on image type
 *
 */

public final class ImageFileIcon extends FileView {

	//Associate ImageIcon type with the image at this location
	ImageIcon gif = new ImageIcon("src/images/GIF_Icon.png");
	ImageIcon jpg = new ImageIcon("src/images/JPG_Icon.png");
	ImageIcon png = new ImageIcon("src/images/PNG_Icon.png");
	ImageIcon tiff = new ImageIcon("src/images/TIFF_Icon.png");


	public final String getName(File file) {
		return null;
	}

	//This method determines what extension type an image has
	public final String getTypeDescription(final File file) {
		String extension = Types.getExtension(file);
		String extType = null;

		if (extension != null) {
			if (extension.equals(Types.gif)){
				extType = "GIF Extension";
			} 
			else 
				if (extension.equals(Types.jpeg) ||
						extension.equals(Types.jpg)) {
					extType = "JPEG Extension";
				} 
				else 
					if (extension.equals(Types.png)){
						extType = "PNG Extension";
					} 
					else 
						if (extension.equals(Types.tiff) ||
								extension.equals(Types.tif)) {
							extType = "TIFF Extension";
						}
		}
		return extType;
	}

	//This method associates the image type with the icon 
	public final Icon getIcon(final File file) {
		String extension = Types.getExtension(file);
		Icon icon = null;

		if (extension != null) {
			if (extension.equals(Types.jpeg) ||
					extension.equals(Types.jpg)) {
				icon = jpg;
			} else 
				if (extension.equals(Types.gif)) {
					icon = gif;
				} else 
					if (extension.equals(Types.tif) ||
							extension.equals(Types.tiff)) {
						icon = tiff;
					} else 
						if (extension.equals(Types.png)) {
							icon = png;
						}
		}
		return icon;
	}
}